<?php

class Log
{

    static protected $writers = array();

    /**
     * get log writer
     */
    static public function instance($name = 'default')
    {
        return isset(self::$writers[$name]) ? self::$writers[$name] : (self::$writers[$name] = self::factory($name));
    }

    static public function factory($name)
    {
        $config = Agi::load_config('log.php');

        if (!isset($config[$name]))
        {
            throw new Exception('log configuration for name does not exists!');
        }

        $config = $config[$name];

        $class = 'Log_' . ucfirst($config['driver']);
        return new $class($config);
    }

    /**
     * write a message to default logger writer.
     */
    static public function write($message)
    {
        return self::instance() -> write($message);
    }
    
}
